package com.hsd.whb.converter;

import com.hsd.whb.entity.Device;
import com.hsd.whb.enums.DeviceStatusEnum;
import com.hsd.whb.service.ManagerService;
import com.hsd.whb.utils.BeanUtil;
import com.hsd.whb.pojo.output.DeviceVO;
import com.wangjiacai.utils.utils.EnumUtil;

import java.util.ArrayList;
import java.util.List;

public class DeviceConverter {

    public static DeviceVO convertToDeviceVO(Device device) {
        DeviceVO deviceVO = new DeviceVO();
        BeanUtil.copyProperties(device, deviceVO);
        deviceVO.setDeviceStatus(EnumUtil.getMessageByCode(device.getDeviceStatus(), DeviceStatusEnum.class));
        return deviceVO;
    }

    public static DeviceVO convertToDeviceVO(Device device, ManagerService managerService) {
        DeviceVO deviceVO = new DeviceVO();
        BeanUtil.copyProperties(device, deviceVO);
        if (device.getManagerId() != null) {
            deviceVO.setManagerName(managerService.findById(device.getManagerId()).getUsername());
        } else {
            deviceVO.setManagerName("");
        }
        deviceVO.setDeviceStatus(EnumUtil.getMessageByCode(device.getDeviceStatus(), DeviceStatusEnum.class));
        return deviceVO;
    }

    public static List<DeviceVO> convertToDeviceVOList(List<Device> devices) {
        List<DeviceVO> list = new ArrayList<>();
        for (Device device : devices) {
            list.add(convertToDeviceVO(device));
        }
        return list;
    }

    public static List<DeviceVO> convertToDeviceVOList(List<Device> devices, ManagerService managerService) {
        List<DeviceVO> list = new ArrayList<>();
        for (Device device : devices) {
            list.add(convertToDeviceVO(device, managerService));
        }
        return list;
    }
}
